package com.situ.controller;


import com.situ.bean.User;

import com.situ.service.impl.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/users")
public class AdminUserController {

    @Autowired
    private UserService userService;

    // 获取所有用户
    @GetMapping
    public List<User> getAllUsers() {
        return userService.getAllUsers();
    }

    // 根据ID获取用户
    @GetMapping("/{id}")
    public User getUserById(@PathVariable int id) {
        return userService.getUserById(id);
    }



    // 更新用户
    @PutMapping("/{id}")
    public User updateUser(@PathVariable int id, @RequestBody User userDetails) {
         userDetails.setId(id);
        userService.updateUser(userDetails);
        System.out.println("updateUser");
        return  userService.getUserById(id);
    }

    // 删除用户
    @DeleteMapping("/{id}")
    public void deleteUser(@PathVariable int id) {
        System.out.println("deleteUser");
        userService.deleteUserById(id);
    }
}